using System;
using System.Collections.Generic;
using System.Text;

namespace Chapter6CustomControlsCS
{
    public class BookToString : System.ComponentModel.TypeConverter
    {
         public override object ConvertFrom(
           System.ComponentModel.ITypeDescriptorContext context,
           System.Globalization.CultureInfo culture, object value)
        {
         Book bk;
         string strBookSerialized;

         bk = (Book) value;
         strBookSerialized = bk.ISBN + "*" + bk.CustomerRating + "*";

         return strBookSerialized;
        }

        public override object ConvertTo(
          System.ComponentModel.ITypeDescriptorContext context,
          System.Globalization.CultureInfo culture,
          object value, System.Type destinationType)
        {
            Book bk;
            string strValue;
            string [] strProps;

            strValue = (string) value;
            strProps = strValue.Split(new Char [] { '*' });
            bk = new Book(strProps[0]);
            bk.Description = strProps[1];

            return bk;
        }        
    }

   
}
